import java.util.Scanner;

public class text1 {
    //给定一个有序整型数组, 实现二分查找
    public static int seek(int[] arry, int target) {
        int left = 0, right = arry.length - 1;
        while (left <= right) {
            int mid = left + (right-left) / 2;
            if (arry[mid] < target ) left = mid + 1;
            else if (arry[mid] > target) right = mid - 1;
            else return mid;
        }
        return -1;
    }
        public static void main (String[] args){
            Scanner sc = new Scanner(System.in);
            System.out.print("请输入数组大小：");
            int n = sc.nextInt();
            System.out.print("请输入你要查找的数字：");
            int target = sc.nextInt();
            int[]arry = new int[n];
            for (int i = 0; i < n; i++) {
                arry[i] = sc.nextInt();
            }
            int address = seek(arry, target);
            System.out.println("目标元素下标是："+address);
        }
    }

